package com.itheima.demo02;

import java.util.*;
import java.util.stream.Stream;

//创建stream流
public class StreamClass04 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>(List.of("a","b","c"));
        Stream<String> stream1 = list.stream();
        stream1.forEach(s -> System.out.println(s));

        System.out.println("-----------------------------");

        Set<String> set = new HashSet<>(Set.of("a","b","c"));
        Stream<String> stream2 = set.stream();
        stream2.forEach(s -> System.out.println(s));

        System.out.println("-----------------------------");

        Map<String,Integer> map = new HashMap<>(Map.ofEntries(Map.entry("zhangsan",23),Map.entry("lisi",24)));
        Stream<String> stream3 = map.keySet().stream();
        Stream<Map.Entry<String, Integer>> stream4 = map.entrySet().stream();
        stream3.forEach(s -> System.out.println(s));
        stream4.forEach(s -> System.out.println(s));

        System.out.println("-----------------------------");

        //同种类型的多个数据可以通过Stream接口的静态方法of(T... values)生成流
        Stream<String> stream5 = Stream.of("a", "b", "c");
        stream5.forEach(s -> System.out.println(s));

        System.out.println("-----------------------------");

        //数组可以通过Arrays中的静态方法stream生成流
        String[] str = {"a","b","c"};
        Stream<String> stream6 = Arrays.stream(str);
        stream6.forEach(s -> System.out.println(s));
    }
}
